﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using System.Collections;

namespace DALL.SysManage
{
    public class T_PUB_WEDDINGTHEME
    {
        public T_PUB_WEDDINGTHEME()
        { }

        /// <summary>
        /// 获取主题婚礼标题智能提示
        /// </summary>
        /// <param name="branch_id"></param>
        /// <returns></returns>
        public DataSet GetThemeWeddingTitel(int branch_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DISTINCT TITLE FROM T_PUB_WEDDINGTHEME ");
            strSql.Append(" where BRANCH_ID=" + branch_id);
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public DataSet GetThemeWeddingTitel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DISTINCT TITLE FROM T_PUB_WEDDINGTHEME ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public void Add(Model.SysManage.T_PUB_WEDDINGTHEME model, IList<Model.Progect.T_PUB_FILE> addLsit, IList<Model.Progect.T_PUB_FILE> editList, IList<Model.Order.T_PUB_Order_Projectcs> PorjectList)
        {
            ArrayList strArry = new ArrayList();

            #region 添加主题婚礼
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.ID != null)
            {
                strSql1.Append("ID,");
                strSql2.Append("'" + model.ID + "',");
            }
            if (model.BRANCH_ID != null)
            {
                strSql1.Append("BRANCH_ID,");
                strSql2.Append("" + model.BRANCH_ID + ",");
            }
            if (model.TITLE != null)
            {
                strSql1.Append("TITLE,");
                strSql2.Append("'" + model.TITLE + "',");
            }
            if (model.DESCRIPTION != null)
            {
                strSql1.Append("DESCRIPTION,");
                strSql2.Append("'" + model.DESCRIPTION + "',");
            }
            if (model.WEDDING_COLOR != null)
            {
                strSql1.Append("WEDDING_COLOR,");
                strSql2.Append("'" + model.WEDDING_COLOR + "',");
            }
            if (model.WEDDING_PRICE != null)
            {
                strSql1.Append("WEDDING_PRICE,");
                strSql2.Append("" + model.WEDDING_PRICE + ",");
            }
            if (model.WEDDING_MONTH != null)
            {
                strSql1.Append("WEDDING_MONTH,");
                strSql2.Append("'" + model.WEDDING_MONTH + "',");
            }
            if (model.WEDDING_STYLE != null)
            {
                strSql1.Append("WEDDING_STYLE,");
                strSql2.Append("'" + model.WEDDING_STYLE + "',");
            }
            if (model.HOTEL_NAME != null)
            {
                strSql1.Append("HOTEL_NAME,");
                strSql2.Append("'" + model.HOTEL_NAME + "',");
            }
            if (model.FLAG != null)
            {
                strSql1.Append("FLAG,");
                strSql2.Append("" + (model.FLAG ? 1 : 0) + ",");
            }
            if (model.FILE_URL != null)
            {
                strSql1.Append("FILE_URL,");
                strSql2.Append("'" + model.FILE_URL + "',");
            }
            if (model.UP_TIME != null)
            {
                strSql1.Append("UP_TIME,");
                strSql2.Append("'" + model.UP_TIME + "',");
            }
            if (model.Type != null)
            {
                strSql1.Append("Type,");
                strSql2.Append("'" + model.Type + "',");
            }
            strSql.Append("insert into T_PUB_WEDDINGTHEME(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strArry.Add(strSql);
            strArry.AddRange(UpdateFile(addLsit, editList, model));
            strArry.AddRange(UpdateProject(PorjectList, model));
            DBHelper.ExecuteSqlTran(strArry);
            #endregion
        }

        /// <summary>
        /// 删除全部和添加新的主题婚礼文件
        /// </summary>
        /// <param name="FileLsit"></param>
        /// <param name="models"></param>
        /// <returns></returns>
        private ArrayList UpdateFile(IList<Model.Progect.T_PUB_FILE> addList, IList<Model.Progect.T_PUB_FILE> editList, Model.SysManage.T_PUB_WEDDINGTHEME models)
        {
            ArrayList arry = new ArrayList();
            string strDel = string.Format(" delete T_PUB_PROJECTFILE where FILE_ID='{0}'", models.ID);
            Model.Progect.T_PUB_FILE model;
            string strFileID = "";
            arry.Add(strDel);

            #region 更新编辑
            for (int i = 0; i < editList.Count; i++)
            {
                model = editList[i];
                strFileID += "'" + model.FILE_ID + "',";
                StringBuilder strSql = new StringBuilder();
                StringBuilder strSql1 = new StringBuilder();
                StringBuilder strSql2 = new StringBuilder();
                if (model.FILE_ID != null)
                {
                    strSql1.Append("PROJECT_ID,");
                    strSql2.Append("'" + model.FILE_ID + "',");
                }
                if (models.ID != null)
                {
                    strSql1.Append("FILE_ID,");
                    strSql2.Append("'" + models.ID + "',");
                }
                strSql.Append("insert into T_PUB_PROJECTFILE(");
                strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
                strSql.Append(")");
                strSql.Append(" values (");
                strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
                strSql.Append(")");
                arry.Add(strSql);

                #region 更新文件表为主题婚礼
                //StringBuilder strSqlw = new StringBuilder();
                //strSqlw.Append("update T_PUB_FILE set ");

                //strSqlw.Append("ISFLAG=" + (model.ISFLAG ? 1 : 0) + ",");

                //if (model.FILE_FORM != null)
                //{
                //    strSqlw.Append("FILE_FORM='" + model.FILE_FORM + "',");
                //}
                //else
                //{
                //    strSqlw.Append("FILE_FORM= null ,");
                //}
                //int n = strSqlw.ToString().LastIndexOf(",");
                //strSqlw.Remove(n, 1);
                //strSqlw.Append(" where FILE_ID='" + model.FILE_ID + "' ");
                //arry.Add(strSqlw);
                #endregion

                #region 更新文件属性表
                //StringBuilder strSqlf = new StringBuilder();
                //strSqlf.Append("update T_PUB_FILEATTRIBUTE set ");
                //if (models.WEDDING_COLOR != null)
                //{
                //    strSqlf.Append("COLOR='" + models.WEDDING_COLOR + "',");
                //}
                //else
                //{
                //    strSqlf.Append("COLOR= null ,");
                //}
                //if (models.WEDDING_PRICE != null)
                //{
                //    strSqlf.Append("WEDDING_PRICE='" + models.WEDDING_PRICE + "',");
                //}
                //else
                //{
                //    strSqlf.Append("WEDDING_PRICE= null ,");
                //}
                //if (models.WEDDING_MONTH != null)
                //{
                //    strSqlf.Append("WEDDING_MONTH='" + models.WEDDING_MONTH + "',");
                //}
                //else
                //{
                //    strSqlf.Append("WEDDING_MONTH= null ,");
                //}
                //if (models.WEDDING_STYLE != null)
                //{
                //    strSqlf.Append("STYLE='" + models.WEDDING_STYLE + "',");
                //}
                //else
                //{
                //    strSqlf.Append("STYLE= null ,");
                //}
                //if (models.HOTEL_NAME != null)
                //{
                //    strSqlf.Append("HOTEL_NAME='" + models.HOTEL_NAME + "',");
                //}
                //else
                //{
                //    strSqlf.Append("HOTEL_NAME= null ,");
                //}
                //int n = strSqlf.ToString().LastIndexOf(",");
                //strSqlf.Remove(n, 1);
                //strSqlf.Append(" where FILE_ID='" + model.FILE_ID + "' ");
                //arry.Add(strSqlf);
                #endregion
            }
            #endregion

            #region 更新文件属性表
            if (strFileID != "")
            {
                //int m = strFileID.LastIndexOf(",");
                strFileID = strFileID.Substring(0, strFileID.Length - 1);
                StringBuilder strSqlf = new StringBuilder();
                strSqlf.Append("update T_PUB_FILEATTRIBUTE set ");
                if (models.WEDDING_COLOR != null)
                {
                    strSqlf.Append("COLOR='" + models.WEDDING_COLOR + "',");
                }
                else
                {
                    strSqlf.Append("COLOR= null ,");
                }
                if (models.WEDDING_PRICE != null)
                {
                    strSqlf.Append("WEDDING_PRICE='" + models.WEDDING_PRICE + "',");
                }
                else
                {
                    strSqlf.Append("WEDDING_PRICE= null ,");
                }
                if (models.WEDDING_MONTH != null)
                {
                    strSqlf.Append("WEDDING_MONTH='" + models.WEDDING_MONTH + "',");
                }
                else
                {
                    strSqlf.Append("WEDDING_MONTH= null ,");
                }
                if (models.WEDDING_STYLE != null)
                {
                    strSqlf.Append("STYLE='" + models.WEDDING_STYLE + "',");
                }
                else
                {
                    strSqlf.Append("STYLE= null ,");
                }
                if (models.HOTEL_NAME != null)
                {
                    strSqlf.Append("HOTEL_NAME='" + models.HOTEL_NAME + "',");
                }
                else
                {
                    strSqlf.Append("HOTEL_NAME= null ,");
                }
                int n = strSqlf.ToString().LastIndexOf(",");
                strSqlf.Remove(n, 1);
                strSqlf.Append(" where FILE_ID in " + "(" + strFileID + ")");
                arry.Add(strSqlf);
            }
            #endregion

            if (strFileID != "")
            {
                strFileID += ",";
            }

            #region 更新添加
            for (int i = 0; i < addList.Count; i++)
            {
                model = addList[i];
                strFileID += "'" + model.FILE_ID + "',";
                StringBuilder strSql = new StringBuilder();
                StringBuilder strSql1 = new StringBuilder();
                StringBuilder strSql2 = new StringBuilder();
                if (model.FILE_ID != null)
                {
                    strSql1.Append("PROJECT_ID,");
                    strSql2.Append("'" + model.FILE_ID + "',");
                }
                if (models.ID != null)
                {
                    strSql1.Append("FILE_ID,");
                    strSql2.Append("'" + models.ID + "',");
                }
                strSql.Append("insert into T_PUB_PROJECTFILE(");
                strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
                strSql.Append(")");
                strSql.Append(" values (");
                strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
                strSql.Append(")");
                arry.Add(strSql);
            }
            #endregion

            #region 添加文件属性表
            foreach (Model.Progect.T_PUB_FILE item in addList)
            {
                #region 添加文件属性
                StringBuilder strSqlaf = new StringBuilder();
                StringBuilder strSqlaf1 = new StringBuilder();
                StringBuilder strSqlaf2 = new StringBuilder();
                if (item.FILE_ID != null)
                {
                    strSqlaf1.Append("FILE_ID,");
                    strSqlaf2.Append("'" + item.FILE_ID + "',");
                }
                if (models.WEDDING_COLOR != null)
                {
                    strSqlaf1.Append("COLOR,");
                    strSqlaf2.Append("'" + models.WEDDING_COLOR + "',");
                }
                if (models.WEDDING_PRICE != null)
                {
                    strSqlaf1.Append("WEDDING_PRICE,");
                    strSqlaf2.Append("'" + models.WEDDING_PRICE + "',");
                }
                if (models.WEDDING_MONTH != null)
                {
                    strSqlaf1.Append("WEDDING_MONTH,");
                    strSqlaf2.Append("'" + models.WEDDING_MONTH + "',");
                }
                if (models.WEDDING_STYLE != null)
                {
                    strSqlaf1.Append("STYLE,");
                    strSqlaf2.Append("'" + models.WEDDING_STYLE + "',");
                }
                if (models.HOTEL_NAME != null)
                {
                    strSqlaf1.Append("HOTEL_NAME,");
                    strSqlaf2.Append("'" + models.HOTEL_NAME + "',");
                }
                strSqlaf.Append("insert into T_PUB_FILEATTRIBUTE(");
                strSqlaf.Append(strSqlaf1.ToString().Remove(strSqlaf1.Length - 1));
                strSqlaf.Append(")");
                strSqlaf.Append(" values (");
                strSqlaf.Append(strSqlaf2.ToString().Remove(strSqlaf2.Length - 1));
                strSqlaf.Append(")");
                arry.Add(strSqlaf);
                #endregion
            }
            #endregion

            #region 更新文件表为已设定
            if (strFileID!="")
            {
                strFileID = strFileID.Substring(0, strFileID.Length - 1);
                StringBuilder strSqlw = new StringBuilder();
                strSqlw.Append("update T_PUB_FILE set ");
                strSqlw.Append("ISFLAG='1',");
                strSqlw.Append("FILE_FORM= case  when  (charindex('6',FILE_FORM)<=0) then FILE_FORM+'6,' when (FILE_FORM IS NULL) then '6,' else  FILE_FORM end ");
                strSqlw.Append(" where FILE_ID in " + "(" + strFileID + ")");
                arry.Add(strSqlw);
            }
         
            #endregion

            return arry;
        }

        /// <summary>
        /// 删除全部和新添主题婚礼项目
        /// </summary>
        /// <param name="FileLsit"></param>
        /// <param name="modelss"></param>
        /// <returns></returns>
        private ArrayList UpdateProject(IList<Model.Order.T_PUB_Order_Projectcs> FileLsit, Model.SysManage.T_PUB_WEDDINGTHEME models)
        {
            ArrayList arry = new ArrayList();
            string strDel = string.Format(" delete T_PUB_Order_Project where OriderID='{0}'", models.ID);
            Model.Order.T_PUB_Order_Projectcs model;
            arry.Add(strDel);
            for (int i = 0; i < FileLsit.Count; i++)
            {
                model = FileLsit[i];
                StringBuilder strSql = new StringBuilder();
                StringBuilder strSql1 = new StringBuilder();
                StringBuilder strSql2 = new StringBuilder();
                if (model.OriderID != null)
                {
                    strSql1.Append("OriderID,");
                    strSql2.Append("'" + model.OriderID + "',");
                }
                if (model.ProjectID != null)
                {
                    strSql1.Append("ProjectID,");
                    strSql2.Append("'" + model.ProjectID + "',");
                }
                if (model.Number != null)
                {
                    strSql1.Append("Number,");
                    strSql2.Append("" + model.Number + ",");
                }
                if (model.Remark != null)
                {
                    strSql1.Append("Remark,");
                    strSql2.Append("'" + model.Remark + "',");
                }
                strSql.Append("insert into T_PUB_Order_Project(");
                strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
                strSql.Append(")");
                strSql.Append(" values (");
                strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
                strSql.Append(")");
                arry.Add(strSql);
            }
            return arry;
        }

        public void Update(Model.SysManage.T_PUB_WEDDINGTHEME model, IList<Model.Progect.T_PUB_FILE> addLsit, IList<Model.Progect.T_PUB_FILE> editList, IList<Model.Order.T_PUB_Order_Projectcs> PorjectList)
        {
            ArrayList strArry = new ArrayList();
            #region 更新主题婚礼
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_WEDDINGTHEME set ");
            if (model.BRANCH_ID != null)
            {
                strSql.Append("BRANCH_ID=" + model.BRANCH_ID + ",");
            }
            else
            {
                strSql.Append("BRANCH_ID= null ,");
            }
            if (model.TITLE != null)
            {
                strSql.Append("TITLE='" + model.TITLE + "',");
            }
            else
            {
                strSql.Append("TITLE= null ,");
            }
            if (model.DESCRIPTION != null)
            {
                strSql.Append("DESCRIPTION='" + model.DESCRIPTION + "',");
            }
            else
            {
                strSql.Append("DESCRIPTION= null ,");
            }
            if (model.WEDDING_COLOR != null)
            {
                strSql.Append("WEDDING_COLOR='" + model.WEDDING_COLOR + "',");
            }
            else
            {
                strSql.Append("WEDDING_COLOR= null ,");
            }
            if (model.WEDDING_PRICE != null)
            {
                strSql.Append("WEDDING_PRICE=" + model.WEDDING_PRICE + ",");
            }
            else
            {
                strSql.Append("WEDDING_PRICE= null ,");
            }
            if (model.WEDDING_MONTH != null)
            {
                strSql.Append("WEDDING_MONTH='" + model.WEDDING_MONTH + "',");
            }
            else
            {
                strSql.Append("WEDDING_MONTH= null ,");
            }
            if (model.WEDDING_STYLE != null)
            {
                strSql.Append("WEDDING_STYLE='" + model.WEDDING_STYLE + "',");
            }
            else
            {
                strSql.Append("WEDDING_STYLE= null ,");
            }
            if (model.HOTEL_NAME != null)
            {
                strSql.Append("HOTEL_NAME='" + model.HOTEL_NAME + "',");
            }
            else
            {
                strSql.Append("HOTEL_NAME= null ,");
            }
            if (model.FLAG != null)
            {
                strSql.Append("FLAG=" + (model.FLAG ? 1 : 0) + ",");
            }
            else
            {
                strSql.Append("FLAG= null ,");
            }
            if (model.FILE_URL != null)
            {
                strSql.Append("FILE_URL='" + model.FILE_URL + "',");
            }
            else
            {
                strSql.Append("FILE_URL= null ,");
            }
            if (model.UP_TIME != null)
            {
                strSql.Append("UP_TIME='" + model.UP_TIME + "',");
            }
            else
            {
                strSql.Append("UP_TIME= null ,");
            }
            if (model.Type != null)
            {
                strSql.Append("Type='" + model.Type + "',");
            }
            else
            {
                strSql.Append("Type= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");
            strSql.Remove(n, 1);
            strSql.Append(" where ID='" + model.ID + "' ");

            strArry.Add(strSql);
            strArry.AddRange(UpdateFile(addLsit, editList, model));
            strArry.AddRange(UpdateProject(PorjectList, model));
            DBHelper.ExecuteSqlTran(strArry);
            #endregion
        }
        /// <summary>
        ///获得主题婚礼和图片
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataTable GetThemmFile(string strWhere)
        {
            StringBuilder varname1 = new StringBuilder();
            varname1.Append("SELECT T_PUB_WEDDINGTHEME.ID, T_PUB_WEDDINGTHEME.FILE_URL,\n");
            varname1.Append("       T_PUB_WEDDINGTHEME.TITLE, \n");
            varname1.Append("       T_PUB_FILE.URLOriginal, \n");
            varname1.Append("       T_PUB_FILE.URLThumbnail, \n");
            varname1.Append("       T_PUB_FILE.URLVideoPhoto, \n");
            varname1.Append("       T_PUB_FILE.TYPE \n");
            varname1.Append("FROM   T_PUB_WEDDINGTHEME, \n");
            varname1.Append("       T_PUB_PROJECTFILE, \n");
            varname1.Append("       dbo.T_PUB_FILE \n");
            varname1.Append("WHERE  T_PUB_WEDDINGTHEME.ID = T_PUB_PROJECTFILE.FILE_ID \n");
            varname1.Append("       AND T_PUB_PROJECTFILE.PROJECT_ID = T_PUB_FILE.FILE_ID ");
            if (strWhere!="")
            {
                varname1.Append(strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase();
            return db.ExecuteDataSet(CommandType.Text, varname1.ToString()).Tables[0];
        }

        #region  Method

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.SysManage.T_PUB_WEDDINGTHEME model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_PUB_WEDDINGTHEME(");
            strSql.Append("ID,BRANCH_ID,TITLE,DESCRIPTION,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,HOTEL_NAME,FLAG)");

            strSql.Append(" values (");
            strSql.Append("@ID,@BRANCH_ID,@TITLE,@DESCRIPTION,@WEDDING_COLOR,@WEDDING_PRICE,@WEDDING_MONTH,@WEDDING_STYLE,@HOTEL_NAME,@FLAG)");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.String, model.ID);
            db.AddInParameter(dbCommand, "BRANCH_ID", DbType.Int32, model.BRANCH_ID);
            db.AddInParameter(dbCommand, "TITLE", DbType.String, model.TITLE);
            db.AddInParameter(dbCommand, "DESCRIPTION", DbType.String, model.DESCRIPTION);
            db.AddInParameter(dbCommand, "WEDDING_COLOR", DbType.String, model.WEDDING_COLOR);
            db.AddInParameter(dbCommand, "WEDDING_PRICE", DbType.Double, model.WEDDING_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_MONTH", DbType.String, model.WEDDING_MONTH);
            db.AddInParameter(dbCommand, "WEDDING_STYLE", DbType.String, model.WEDDING_STYLE);
            db.AddInParameter(dbCommand, "HOTEL_NAME", DbType.String, model.HOTEL_NAME);
            db.AddInParameter(dbCommand, "FLAG", DbType.Boolean, model.FLAG);
            int result;
            object obj = db.ExecuteScalar(dbCommand);
            if (!int.TryParse(obj.ToString(), out result))
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.SysManage.T_PUB_WEDDINGTHEME model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_WEDDINGTHEME set ");
            strSql.Append("BRANCH_ID=@BRANCH_ID,");
            strSql.Append("TITLE=@TITLE,");
            strSql.Append("DESCRIPTION=@DESCRIPTION,");
            strSql.Append("WEDDING_COLOR=@WEDDING_COLOR,");
            strSql.Append("WEDDING_PRICE=@WEDDING_PRICE,");
            strSql.Append("WEDDING_MONTH=@WEDDING_MONTH,");
            strSql.Append("WEDDING_STYLE=@WEDDING_STYLE,");
            strSql.Append("HOTEL_NAME=@HOTEL_NAME,");
            strSql.Append("FLAG=@FLAG");
            strSql.Append(" where ID=@ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.String, model.ID);
            db.AddInParameter(dbCommand, "BRANCH_ID", DbType.Int32, model.BRANCH_ID);
            db.AddInParameter(dbCommand, "TITLE", DbType.String, model.TITLE);
            db.AddInParameter(dbCommand, "DESCRIPTION", DbType.String, model.DESCRIPTION);
            db.AddInParameter(dbCommand, "WEDDING_COLOR", DbType.String, model.WEDDING_COLOR);
            db.AddInParameter(dbCommand, "WEDDING_PRICE", DbType.Double, model.WEDDING_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_MONTH", DbType.String, model.WEDDING_MONTH);
            db.AddInParameter(dbCommand, "WEDDING_STYLE", DbType.String, model.WEDDING_STYLE);
            db.AddInParameter(dbCommand, "HOTEL_NAME", DbType.String, model.HOTEL_NAME);
            db.AddInParameter(dbCommand, "FLAG", DbType.Boolean, model.FLAG);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_PUB_WEDDINGTHEME ");
            strSql.Append(" where ID=@ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.String, ID);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SysManage.T_PUB_WEDDINGTHEME GetModel(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,BRANCH_ID,TITLE,DESCRIPTION,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,HOTEL_NAME,FLAG,FILE_URL,UP_TIME,Type  from T_PUB_WEDDINGTHEME");
            strSql.Append(" where ID=@ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.String, ID);
            Model.SysManage.T_PUB_WEDDINGTHEME model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,BRANCH_ID,TITLE,DESCRIPTION,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,HOTEL_NAME,FLAG,Type ");
            strSql.Append(" FROM T_PUB_WEDDINGTHEME ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase();
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.SysManage.T_PUB_WEDDINGTHEME> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,BRANCH_ID,TITLE,DESCRIPTION,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,HOTEL_NAME,FLAG,FILE_URL,UP_TIME,Type ");
            strSql.Append(" FROM T_PUB_WEDDINGTHEME ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Model.SysManage.T_PUB_WEDDINGTHEME> list = new List<Model.SysManage.T_PUB_WEDDINGTHEME>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.SysManage.T_PUB_WEDDINGTHEME ReaderBind(IDataReader dataReader)
        {
            Model.SysManage.T_PUB_WEDDINGTHEME model = new Model.SysManage.T_PUB_WEDDINGTHEME();
            object ojb;
            model.ID = dataReader["ID"].ToString();
            ojb = dataReader["BRANCH_ID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BRANCH_ID = (int)ojb;
            }
            model.TITLE = dataReader["TITLE"].ToString();
            model.DESCRIPTION = dataReader["DESCRIPTION"].ToString();
            model.WEDDING_COLOR = dataReader["WEDDING_COLOR"].ToString();
            ojb = dataReader["WEDDING_PRICE"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.WEDDING_PRICE = Convert.ToInt32(ojb);
            }
            model.WEDDING_MONTH = dataReader["WEDDING_MONTH"].ToString();
            model.WEDDING_STYLE = dataReader["WEDDING_STYLE"].ToString();
            model.HOTEL_NAME = dataReader["HOTEL_NAME"].ToString();
            ojb = dataReader["FLAG"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.FLAG = (bool)ojb;
            }
            model.FILE_URL = dataReader["FILE_URL"].ToString();
            ojb = dataReader["UP_TIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UP_TIME =Convert.ToDateTime(ojb);
            }
            model.Type = dataReader["Type"].ToString();
            return model;
        }

        #endregion  Method
    }
}
